package xmlParser;

import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Locale;

import org.xml.sax.helpers.AttributesImpl;

public class SAXBean {
	
	public AttributesImpl fAttributes = null; 
	public String fValue = "";
	public Integer[] fPosition = null;
	public String path = "";
	
	public String getAttribute(String name){
		if(fAttributes!=null){
			String f = fAttributes.getValue(name);
			if(f!=null){
				return f;
			}else{
				return "";
			}
		}
		return "";
	}
	
	public String getText(){
		return fValue;
	}
	
	public int getInt(){
		if(fValue!=null && fValue.length()>0){
			return Integer.parseInt(fValue);
		}
		return 0;
	}
	
	public float getFloat(){
		if(fValue!=null && fValue.length()>0){
			try{
				return Float.parseFloat(fValue);
			}catch(Exception e){
				return getInt();
			}
		}
		return 0f;
	}
	
	public float getFloatPrecision(int number){
		float f = getFloat();
		NumberFormat nf = NumberFormat.getInstance(Locale.CHINA);
		nf.setMaximumFractionDigits(number);
		String n = nf.format(f);
		try{
			n = n.replaceAll(",", "");
			return Float.parseFloat(n);
		}catch(Exception e){
			return getInt();
		}
	}
	
	public String toString(){
		return fValue;
	}
	
	public static void main(String[] a){
		SAXBean b = new SAXBean();
		b.fValue="3000";
		System.out.println(b.getFloatPrecision(2));
	}
	
}
